package controller.Seller;

import com.alibaba.fastjson.JSON;
import pojo.Discount;
import pojo.Seller;
import pojo.Smallclass;
import service.Seller.SmallclassService;
import service.Seller.impl.SmallclassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "SmallServlet",urlPatterns = "/SmallServlet")
public class SmallServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String action =request.getParameter("action");
        SmallclassService scl= new SmallclassServiceImpl();
        PrintWriter pw =response.getWriter();
        if(action.equals("select")){
            List<Smallclass> SmallList=scl.addSmallclass();
            String calist= JSON.toJSONStringWithDateFormat(SmallList,"yyyy-MM-dd");
            pw.write(calist);
            pw.flush();
            pw.close();
        }else if(action.equals("select1")){
            List<Seller> SellerllList=scl.addSeller();
            String calists= JSON.toJSONStringWithDateFormat(SellerllList,"yyyy-MM-dd");
            pw.write(calists);
        }else if(action.equals("select2")){
            List<Discount> DiscountlList=scl.addDiscount();
            String calists= JSON.toJSONStringWithDateFormat(DiscountlList,"yyyy-MM-dd");
            pw.write(calists);
        }
        pw.flush();
        pw.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request,response);
    }
}
